home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8941 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  40 lines

  1. Path: news.production.compuserve.com!news
  2. From: Terry Nikkel <102101.2325@CompuServe.COM>
  3. Newsgroups: comp.lang.c++
  4. Subject: Help needed: reference parameter
  5. Date: 27 Feb 1996 15:17:41 GMT
  6. Organization: SACDA, Inc.
  7. Message-ID: <4gv7al$o0c$1@mhafc.production.compuserve.com>
  8.  
  9. I am posting this for a colleague, thanks for your help:
  10. I want to pass a reference (default 0) parameter to a function.  
  11. For example, assume classes 'AClass' and 'BClass'; assume 
  12. 'AClass' has a method called 'Function'.
  13.  
  14. //AClass.hxx
  15. #include "BClass.hxx"
  16. bool AClass::Function (BClass& = 0);  // would be the 
  17. specification
  18.  
  19. //AClass.cxx
  20. bool AClass::Function (BClass& refer)  // is the actual method
  21. {
  22.     if (! (refer == 0)  {
  23.         ...
  24.     {
  25. }
  26.  
  27. The problem is the specification does not work.  To accommodate 
  28. the above I have a constructor for BClass that takes an int 
  29. (BClass(const int) {} ), as well as operator==(const int).
  30. I would have thought this was enough, but the compiler errors 
  31. with the message "initial value of reference to non-const has 
  32. incorrect type" on "BClass& = 0);".  What am I doing wrong?
  33. Terry Nikkel:  email terry.l.nikkel@ontario.honeywell.com
  34.  
  35. -- 
  36. Terry Nikkel
  37. Information Specialist
  38. SACDA, Inc., London, Ontario N6B 1V5
  39. tnikkel@p01.on49.honeywell.com
  40.